package com.jicheng.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jicheng.Utils.ResultMess;
import com.jicheng.dto.app.AppDateDto;
import com.jicheng.dto.logs.LogsDetailDto;
import com.jicheng.dto.logs.LogsDto;
import com.jicheng.ext.dto.PagingResult;
import com.jicheng.ext.dto.SearchPagingParams;
import com.jicheng.service.LogsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: TaskController
 * @Description: TODO
 * @author: khz
 * @date: 2020年09月04日 10:14
 */
@Api(tags = "日志管理")
@RequestMapping("/log")
@RestController
public class LogController {

    @Autowired
    LogsService logsService;
    @GetMapping("/getLog")
    @ApiOperation(value = "获取app操作日志列表")
    public PagingResult<LogsDto> getLog(SearchPagingParams searchPagingParams, String username, String startTime, String endTime){
        PageHelper.startPage(searchPagingParams.getPage(), searchPagingParams.getPageSize());

        List<LogsDto> list = logsService.getLog(username,startTime,endTime);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult<LogsDto> result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
      return result;
    }

    @GetMapping("/getLogDetali")
    @ApiOperation(value = "获取app操作日志详情列表")
    public PagingResult<LogsDetailDto> getLogDetali(SearchPagingParams searchPagingParams, String operationId, String startTime, String endTime){
        PageHelper.startPage(searchPagingParams.getPage(), searchPagingParams.getPageSize());

        List<LogsDetailDto> list = logsService.getLogDetali(operationId,startTime,endTime);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult<LogsDetailDto> result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return result;
    }

    @GetMapping("/getSysLog")
    @ApiOperation(value = "获取系统操作日志列表")
    public PagingResult<LogsDto> getSysLog(SearchPagingParams searchPagingParams, String username, String startTime, String endTime){
        PageHelper.startPage(searchPagingParams.getPage(), searchPagingParams.getPageSize());

        List<LogsDto> list = logsService.getSysLog(username,startTime,endTime);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult<LogsDto> result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return result;
    }

    @GetMapping("/getSysLogDetali")
    @ApiOperation(value = "获取系统操作日志详情列表")
    public PagingResult<LogsDetailDto> getSysLogDetali(SearchPagingParams searchPagingParams, @RequestParam String tokenId, String startTime, String endTime){
        PageHelper.startPage(searchPagingParams.getPage(), searchPagingParams.getPageSize());

        List<LogsDetailDto> list = logsService.getSysLogDetali(tokenId,startTime,endTime);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult<LogsDetailDto> result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return result;
    }

}
